import os

# 训练图像文件夹路径
train_images_folder = "datasets/rcs_trainval_0702/images/train"
val_images_folder = "datasets/rcs_trainval_0702/images/val"
# 生成的train.txt文件路径
train_txt_path = "datasets/rcs_trainval_0702/dataSet/train.txt"
val_txt_path = "datasets/rcs_trainval_0702/dataSet/val.txt"
# 获取训练图像文件夹中所有图像文件的路径
train_image_files = [os.path.join(train_images_folder, file) for file in os.listdir(train_images_folder) if file.endswith(('.jpg', '.jpeg', '.png', '.gif'))]
val_image_files = [os.path.join(val_images_folder, file) for file in os.listdir(val_images_folder) if file.endswith(('.jpg', '.jpeg', '.png', '.gif'))]
# 写入train.txt文件
with open(train_txt_path, 'w') as f:
    f.write('\n'.join(train_image_files))
# 写入val.txt文件
with open(val_txt_path, 'w') as f:
    f.write('\n'.join(val_image_files))
print("txt已成功生成。")
